<?php

namespace app\common\controller;
use think\Controller;
class ApiController extends Controller
{
    protected function returnSuccess($msg, $data=null)
    {
        return [
            'code' => 1,
            'msg' => $msg,
            'data' => $data,
        ];
    }
    protected function returnError($msg)
    {
        return [
            'code' => 0,
            'msg' => $msg,
        ];
    }
    protected function returnData($data)
    {
        return [
            'code' => 1,
            'data' => $data,
        ];
    }
    public function handleValidate($data, $rule)
    {
        $result = $this->validate($data, $rule);
        if (true !== $result)
            exception($result);

//        $validate = new \think\Validate;
//        $validate->rule($rule);
//        if (!$validate->check($data)) {
//            exception($validate->getError());
//        }
    }
}
